package jdir.util;

import java.text.MessageFormat;
import java.util.Locale;
import java.util.ResourceBundle;

/**
 * Helperclass to get the right message to the given nls string. Therefore a
 * fitting messages_language_country.properties file is necessary
 */
public class MessagesUtil 
{
	private static final Locale LOCALE = Locale.getDefault();
	
	private static ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle("jdir.nls.messages", LOCALE);
	
	/**
	 * Fetches the message according to the current default locale settings
	 * @param key key of the message
	 * @param args additional arguments
	 * @return message in the locale language
	 */
	public static String getMessage(String key, Object... args) 
	{
		final String msgPattern = RESOURCE_BUNDLE.getString(key);
		MessageFormat formatter = new MessageFormat(msgPattern);
		String msg = formatter.format(args);
		return msg;
	}
}
